package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.CustomerTransfer;
import cn.wolfcode.rbac.mapper.CustomerMapper;
import cn.wolfcode.rbac.mapper.CustomerTransferMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.ICustomerTransferService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CustomerTransferServiceImpl implements ICustomerTransferService {
    @Autowired
    private CustomerTransferMapper CustomertransferMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    @Transactional(readOnly = true)
    public PageInfo query(QueryObject paramQueryObject) {
        PageHelper.startPage(paramQueryObject.getCurrentPage(), paramQueryObject.getPageSize());
        List<CustomerTransfer> list = this.CustomertransferMapper.selectForList(paramQueryObject);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(CustomerTransfer customertransfer) {
        if (customertransfer.getId() == null) {
            this.CustomertransferMapper.insert(customertransfer);
            System.out.println("===============================");
        } else {
            this.CustomertransferMapper.updateByPrimaryKey(customertransfer);
            System.out.println("1111111111111111111111111111111");
        }
        if (customertransfer.getSellerId() != null) {
            customerMapper.updateSeller(customertransfer.getCustomerId(), customertransfer.getSellerId());
        }
    }

    @Override
    public void delete(Long paramLong) {
        this.CustomertransferMapper.deleteByPrimaryKey(paramLong);
    }

    @Override
    @Transactional(readOnly = true)
    public CustomerTransfer get(Long paramLong) {

        return this.CustomertransferMapper.selectByPrimaryKey(paramLong);
    }

    @Override
    @Transactional(readOnly = true)
    public List<CustomerTransfer> list() {
        List<CustomerTransfer> customertransfers = this.CustomertransferMapper.selectAll();
        return customertransfers;
    }
}
